
import moment from 'moment';
import NumberUtils from '@/utils/NumberUtils';

export const DEFAULT_DATE_FORMET = "YYYY-MM-DD";

export const DEFAULT_DATETIME_FORMET = "YYYY-MM-DD HH:mm"

export const DEFAULT_TIME_FORMET = "MM-DD HH:mm"


export const now = () => {
    return moment().format(DEFAULT_DATETIME_FORMET)
}

export const formetDate = (date) => {
    if (!date) {
        return ''
    }
    let m = moment(date);
    if (m.isValid()) {
        return m.format(DEFAULT_DATE_FORMET)
    }
    if (NumberUtils.isPositiveNumber(date)) {
        var timestamp =  parseInt(date);
        return moment(timestamp).format(DEFAULT_DATE_FORMET)
    }
}

export const formetTime = (dateTime) => {
    if (!dateTime) {
        return ''
    }
    let m = moment(dateTime);
    if (m.isValid()) {
        return m.format(DEFAULT_DATETIME_FORMET)
    }
    if (NumberUtils.isPositiveNumber(dateTime)) {
        var timestamp =  parseInt(dateTime);
        return moment(timestamp).format(DEFAULT_DATETIME_FORMET)
    }
}

export const formetTime_MDHm = (dateTime) => {
    if (!dateTime) {
        return ''
    }
    let m = moment(dateTime);
    if (m.isValid()) {
        return m.format(DEFAULT_TIME_FORMET)
    }
    if (NumberUtils.isPositiveNumber(dateTime)) {
        var timestamp =  parseInt(dateTime);
        return moment(timestamp).format(DEFAULT_DATETIME_FORMET)
    }
}


export const parseDate = (string) => {
    if (string) {
        return moment(string)
    }
    return undefined;
}


export const checkRangeDateNotNull = (dates) => {
    if (!dates) {
        return false;
    }
    if (dates[0] && dates[0] !== "" && dates[1] && dates[1] !== "") {
        return true;
    }
    return false;
}
